import collections


class Solution:
    # 方法1 排序后比较
    # def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
    #     nums1.sort(reverse = True)
    #     print(nums1)
    #     nums2.sort(reverse = True)
    #     print(nums2)
    #     rlt = []
    #     while(nums1 and nums2):
    #         if nums1[-1] == nums2[-1]:
    #             rlt.append(nums1[-1])
    #             nums1.pop()
    #             nums2.pop()
    #         elif nums1[-1]>nums2[-1]:
    #             nums2.pop()
    #         else:
    #             nums1.pop()
    #     return rlt



    # 方法2 使用内置计算库
    class Solution:
        def intersect2(self, nums1: List[int], nums2: List[int]) -> List[int]:
            mySet1 = collections.Counter(nums1)
            mySet2 = collections.Counter(nums2)
            rlt = mySet1 & mySet2
            return rlt.elements()